/*
 * File Name：BaseSpeechActivity.java
 * Copyright：Copyright 2008-2014 CiWong.Inc. All Rights Reserved.
 * Description： BaseSpeechActivity.java
 * Modify By：jejun
 * Modify Date：2014-2-11
 * Modify Type：Add
 */
package com.ciwong.epaper.modules.evaluate.ui;

import android.app.Activity;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.PowerManager;
import android.os.PowerManager.WakeLock;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.view.WindowManager;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.ciwong.epaper.R;
import com.ciwong.epaper.application.EApplication;
import com.ciwong.epaper.modules.epaper.bean.Answer;
import com.ciwong.epaper.modules.epaper.bean.CatalogueInfo;
import com.ciwong.epaper.modules.epaper.bean.Module;
import com.ciwong.epaper.modules.epaper.bean.ModuleContent;
import com.ciwong.epaper.modules.epaper.bean.WorkAnswers;
import com.ciwong.epaper.modules.epaper.util.ListenSpeakUtil;
import com.ciwong.epaper.modules.epaper.util.RepeatKeyUtil;
import com.ciwong.epaper.modules.evaluate.bean.AnswerRecorder;
import com.ciwong.epaper.modules.evaluate.bean.RepeatAnswerInfo;
import com.ciwong.epaper.modules.evaluate.bean.WordDetail;
import com.ciwong.epaper.modules.evaluate.util.SpeechUtils;
import com.ciwong.epaper.modules.evaluate.util.UnitSpeechControler;
import com.ciwong.epaper.modules.me.bean.RequirementContent;
import com.ciwong.epaper.modules.me.bean.WorkContents;
import com.ciwong.epaper.modules.me.util.MeJumpManager;
import com.ciwong.epaper.util.EConstants;
import com.ciwong.epaper.util.ESystem;
import com.ciwong.epaper.util.IntentFlag;
import com.ciwong.epaper.util.RequestCode;
import com.ciwong.epaper.util.SerializableManager;
import com.ciwong.epaper.util.download.DownLoadInfo;
import com.ciwong.epaper.widget.PlayStateDubView;
import com.ciwong.epaper.widget.RoundProgressBar;
import com.ciwong.libs.utils.CWSys;
import com.ciwong.mobilelib.bean.UserInfoBase;
import com.ciwong.mobilelib.i.BaseCallBack;
import com.ciwong.mobilelib.i.ViewOnClickListener;
import com.ciwong.mobilelib.ui.BaseActivity;
import com.ciwong.mobilelib.widget.BuyServiceDialog;
import com.ciwong.mobilelib.widget.CWDialog;

import java.util.ArrayList;
import java.util.Timer;
import java.util.TimerTask;
import java.util.UUID;
import java.util.concurrent.CopyOnWriteArrayList;

/**
 * 单词和句子基类
 *
 * @author jejun
 * @version ciwong v.1.0 2014-2-11
 * @since ciwong v.1.0
 */
public abstract class BaseSpeechActivity extends BaseActivity {

    private WakeLock mWakeLock;

    protected float score;

    public boolean isLearn;
    public ArrayList<WordDetail> words;

    protected DownLoadInfo mDownLoadInfo;

    protected Module mModule;

    protected RequirementContent requirementContent;

    protected String checkedResource;

    protected int position;

    protected Answer answer;

    protected boolean isPlayAssess = true;// 是否播放评价语

    protected UnitSpeechControler speechControler;


    protected String intentWorkId = "0";

    protected int workLong;// 总用时

    protected Timer timer;

    protected long startDate = System.currentTimeMillis();// (开始做作业时间)(毫秒)

    protected long startTime;

    protected boolean isTimering;// 是否正在计时
    private RelativeLayout mRlCheckMode, mRlStopOrplay;
    private RelativeLayout ls_back_next_layout;
    protected TextView back_record, next_record;
    protected ImageView playing, recording, iv_stopOrplay, mIvCheckMode;//
    protected RoundProgressBar round_progress_bar;//播放进度

    protected TextView tvNo, tv_count;
    protected ProgressBar progressBar;//整个试卷的进度显示
    protected WordBottomView read_bottom_view;

    protected UserInfoBase userInfo;

    protected String mClassId;

    protected String mVersionId;

    protected int mServiceId;
    protected int mRequestCodeFrom;

    //截止时间
    public long effectiveDate = -1;

    public boolean isRepeatWord;//是否来自于单词重读

    protected WorkContents mWorkContents;
    protected int readMode;//跟读模式
    protected String mUuid = UUID.randomUUID().toString();
    /* =UUID.randomUUID().toString()*/;

    protected int moduleId;

    protected String mResourceName;

    protected String jsonResourcePath;

    protected PlayStateDubView play_dubing_iocn;

    protected ImageView play_iocn, img_stop_recording, img_micro_recording;

    //是否使用手动模式
    public boolean mIsUnAutoMode;

    //是否是考试模式
    public boolean mIsKaoShiMode;

    //是否播录音
    public boolean mIsPlayRecord;

    //是否暂停
    public boolean mIsAutoPlayPause = false;

    private EApplication application;

    /**
     * 默认服务包剩余使用时间
     */
    public boolean serviceExpired;

    @Override
    protected void preCreate() {
        super.preCreate();
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);// 去掉信息栏
        Intent intent = getIntent();
        if (intent != null) {

            isRepeatWord = intent.getBooleanExtra(IntentFlag.INTENT_FLAG_ID, false);
            if (isRepeatWord) {//来自于重读页面
                words = new ArrayList<WordDetail>();
                WordDetail wordDetail = (WordDetail) intent.getSerializableExtra(IntentFlag.INTENT_FLAG_OBJ);
                words.add(wordDetail);
                readMode = intent.getIntExtra(IntentFlag.INTENT_FLAG_TYPE, SpeechUtils.WordReadMode.READ_REPEAT);
                mDownLoadInfo = (DownLoadInfo) intent
                        .getSerializableExtra(IntentFlag.INTENT_FLAG_DOWNLOAD_INFO);
                mUuid = intent.getStringExtra(IntentFlag.INTENT_FLAG_UUID);
                mResourceName = intent.getStringExtra(IntentFlag.INTENT_FLAG_TITLE);
                if (TextUtils.isEmpty(mResourceName) && mDownLoadInfo != null) {
                    mResourceName = mDownLoadInfo.getResourceName();
                }
                mIsUnAutoMode = intent.getBooleanExtra(IntentFlag.INTENT_FLAG_IS_SHOUDONG_MODE, false);
            } else {
                readMode = getIntent().getIntExtra(IntentFlag.INTENT_FLAG_TYPE, SpeechUtils.WordReadMode.READ_REPEAT);
                mDownLoadInfo = (DownLoadInfo) intent
                        .getSerializableExtra(IntentFlag.INTENT_FLAG_DOWNLOAD_INFO);
                mModule = (Module) intent.getSerializableExtra(IntentFlag.INTENT_FLAG_OBJ);
                position = intent.getIntExtra(IntentFlag.INTENT_FLAG_POSITION, 0);

                requirementContent = (RequirementContent) intent
                        .getSerializableExtra(IntentFlag.INTENT_FLAG_REQU_CONTENT);
                checkedResource = intent
                        .getStringExtra(IntentFlag.INTENT_FLAG_CHECKED_RESOURCE);


                String workId = intent
                        .getStringExtra(IntentFlag.INTENT_FLAG_WORK_ID);

                mClassId = intent.getStringExtra(IntentFlag.INTENT_FLAG_CLASS_ID);
                mVersionId = intent.getStringExtra(IntentFlag.INTENT_FLAG_WORK_CONTENT);
                mServiceId = getIntent().getIntExtra(IntentFlag.INTENT_FLAG_SERVICE_ID, -1);
                mRequestCodeFrom = getIntent().getIntExtra(IntentFlag.INTENT_FLAG_REQUEST_CODE_FROM, -1);

                if (mDownLoadInfo.getType() == CatalogueInfo.PackageMode.PACKAGE_MODE_NEW) {

                    jsonResourcePath = ESystem.getPackagesJsonPathNew(mDownLoadInfo);
                    moduleId = Integer.valueOf(mDownLoadInfo.getModuleId());

                    if (null == mVersionId) {
                        mVersionId = mDownLoadInfo.getVersionId();
                    }
                    mResourceName = mDownLoadInfo.getResourceName();
                } else {
                    jsonResourcePath = ESystem.getPackagesJsonPath(mModule.getResourceList().get(position).getResourceFile());
                    ModuleContent moduleContent = mModule.getResourceList().get(position);
                    moduleId = mModule.getModuleInfo().getModuleId();

                    if (null == mVersionId) {
                        mVersionId = moduleContent.getVersionId();
                    }
                    mResourceName = mModule.getResourceList().get(position).getResourceName();

                }


                mWorkContents = (WorkContents) getIntent().getSerializableExtra(IntentFlag.INTENT_FLAG_WORK_CONTENTS);
                if (!TextUtils.isEmpty(workId)) {
                    intentWorkId = workId;
                }
            }

        }
        //获取保存本地的开始时间
        startTime = CWSys.getSharedLong(ListenSpeakUtil.getAnswerStartTimeKey(mDownLoadInfo, mModule, position, intentWorkId), 0);

        if (startTime == 0) {
            if (null != mDownLoadInfo) {
                startTime = mDownLoadInfo.getStartTime();
                CWSys.setSharedLong(ListenSpeakUtil.getAnswerStartTimeKey(mDownLoadInfo, mModule, position, intentWorkId), startTime);
            }
        }

    }

    @Override
    protected void findViews() {
        round_progress_bar = findViewById(R.id.round_progress_bar);
        playing = findViewById(R.id.problemPlay);
        recording = findViewById(R.id.img_micro_recording);
        iv_stopOrplay = findViewById(R.id.iv_stopOrplay);
        mRlStopOrplay = findViewById(R.id.ls_timer_layout);
        tvNo = findViewById(R.id.btn_repeat_read_no);
        tv_count = findViewById(R.id.btn_repeat_read_count);
        progressBar = findViewById(R.id.progressBar);
        read_bottom_view = findViewById(R.id.read_bottom_view);
        mRlCheckMode = findViewById(R.id.rl_check_mode);
        mIvCheckMode = findViewById(R.id.iv_check_mode);
        ls_back_next_layout = findViewById(R.id.ls_back_next_layout);
        back_record = findViewById(R.id.back_record);
        next_record = findViewById(R.id.next_record);
        img_micro_recording = findViewById(R.id.img_micro_recording);
        img_stop_recording = findViewById(R.id.img_stop_recording);
        play_iocn = findViewById(R.id.play_iocn);
        play_dubing_iocn = findViewById(R.id.play_dubing_iocn);
        next_record = findViewById(R.id.next_record);
        //重读没有精读模式
        if (isRepeatWord) {
            mRlCheckMode.setVisibility(View.GONE);
        } else {
            mRlCheckMode.setVisibility(View.VISIBLE);
        }

    }


    @Override
    protected void init() {
        application = (EApplication) getApplication();
        if (application != null) {
            //是否有购买vip
            serviceExpired = application.isServiceExpired();
        }
        if (!serviceExpired) {
            if (mWorkContents != null && mWorkContents.getIsFree() == 1) {
                serviceExpired = true;
            }
        }
        if (null != mWorkContents && mWorkContents.getExamMode() != 0) {
            //考试模式默认自动模式
            mIsUnAutoMode = false;
            mIsKaoShiMode = true;
        }
        if (mRlCheckMode.getVisibility() == View.VISIBLE) {
            if (mIsKaoShiMode) {
                //考试模式不显示切换模式按钮
                mIvCheckMode.setVisibility(View.GONE);
            } else {
                boolean isOpenInstentiveReadingMode = CWSys.getSharedBoolean(EConstants.SHARE_KEY_IS_OPEN_INTENSIVE_READING_MODE, false);
                mIvCheckMode.setVisibility(View.VISIBLE);
                mIvCheckMode.setSelected(isOpenInstentiveReadingMode);
                mIsUnAutoMode = isOpenInstentiveReadingMode;
            }
        }
        //mIvCheckMode.setVisibility(View.GONE);

        setAutoOrUnautoModle();
    }

    /**
     * 设置手动或者自动模式
     */
    protected void setAutoOrUnautoModle() {
        if (mIsUnAutoMode) {
            //手动模式
            mRlStopOrplay.setVisibility(View.GONE);
            ls_back_next_layout.setVisibility(View.VISIBLE);
            if (readMode == SpeechUtils.WordReadMode.READ_REPEAT) {
                play_iocn.setVisibility(View.VISIBLE);
            } else {
                play_iocn.setVisibility(View.GONE);
            }
            img_micro_recording.setVisibility(View.VISIBLE);
            play_dubing_iocn.setVisibility(View.GONE);
        } else {
            //自动模式
            mRlStopOrplay.setVisibility(View.VISIBLE);
            ls_back_next_layout.setVisibility(View.GONE);
            play_iocn.setVisibility(View.GONE);
            img_micro_recording.setVisibility(View.GONE);
            play_dubing_iocn.setVisibility(View.GONE);
        }
    }

    @Override
    protected void initEvent() {
        iv_stopOrplay.setOnClickListener(clickListener);
        mRlCheckMode.setOnClickListener(clickListener);

        back_record.setOnClickListener(clickListener);
        next_record.setOnClickListener(clickListener);

        img_micro_recording.setOnClickListener(clickListener);
        img_stop_recording.setOnClickListener(clickListener);
        play_dubing_iocn.setOnClickListener(clickListener);
        play_iocn.setOnClickListener(clickListener);
    }

    @Override
    protected void onResume() {
        super.onResume();
        mWakeLock = ((PowerManager) getSystemService(Activity.POWER_SERVICE))
                .newWakeLock(
                        PowerManager.SCREEN_BRIGHT_WAKE_LOCK
                                | PowerManager.ON_AFTER_RELEASE,
                        getPackageName());
        mWakeLock.acquire();
        isPlayAssess = CWSys.getSharedBoolean(
                EConstants.SHARE_KEY_IS_ASSESS + getUserInfoBase().getUserId(),
                false);
    }

    /**
     * 开始计时
     */
    protected void startTimer() {
        cancelTimer();
        timer = new Timer();
        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                workLong++;

            }
        }, 0, 1000);
        isTimering = true;
    }

    /**
     * 取消计时
     */
    protected void cancelTimer() {
        if (timer != null && isTimering) {
            timer.cancel();
            isTimering = false;
        }
    }

    @Override
    protected void onPause() {
        super.onPause();
        mWakeLock.release();
    }

    public abstract void goBack();


    /**
     * 设置题号和做题进度
     *
     * @param index
     * @param total
     */
    public void setNo(int index, int total) {
        tvNo.setText("" + index);
        tv_count.setText("/" + total);
        progressBar.setMax(total);
        progressBar.setProgress(index);
    }


    /**
     * 切换到暂停状态(单词)
     */
    public void switchPauseStateForWord() {
        //切换播放暂停按钮 //暂停状态下
        read_bottom_view.setPlayOrPause(false);
        if (mIsUnAutoMode) {
            read_bottom_view.setPlayWordState(false);
        }
    }

    /**
     * 切换到播放状态
     */
    public void switchPlayState() {
        //切换播放暂停按钮 到播放状态
        read_bottom_view.setPlayOrPause(true);
    }

    /**
     * 切换到重启状态
     */
    public void switchRestartState() {
        read_bottom_view.setInitState(mIsUnAutoMode);
    }

    /**
     * 暂停或播放事件
     */
    public abstract void playOrPause(boolean isPause, boolean isNeedRecord);

    /**
     * 暂停或播放事件
     */
    public abstract void reStartPlay();


    @Override
    protected void onActivityResult(int requestCode, int resultCode,
                                    Intent data) {

    }


    /**
     * 获取保存的答案记录
     *
     * @param baseCallBack
     */
    protected void getSaveUserAnswerList(final BaseCallBack baseCallBack, final ArrayList<AnswerRecorder> answerRecorders, String saveUUid) {


        SerializableManager.getInstance().deSerialize(RepeatKeyUtil.getWordRepeatAnswerListKey(mDownLoadInfo, mModule, position, intentWorkId, saveUUid),

                new BaseCallBack() {
                    @Override
                    public void success(Object data) {

                        try {
                            ArrayList<WorkAnswers<RepeatAnswerInfo>> answerList;

                            if (data instanceof CopyOnWriteArrayList) {
                                answerList = new ArrayList<WorkAnswers<RepeatAnswerInfo>>();
                                if (null != data) {
                                    answerList.addAll((ArrayList<WorkAnswers<RepeatAnswerInfo>>) data);
                                }
                            } else {
                                answerList = (ArrayList<WorkAnswers<RepeatAnswerInfo>>) data;
                            }

                            //要进行size 判断是因为用户退出的时候做作业记录跟答案记录缓存可能会不同步，导致下次进来数组越界--neo
                            if (null == answerList || answerRecorders == null) {
                                Log.d(TAG, "#######反序列化成功 但答案数据空#############");
                                baseCallBack.failed(null);
                            } else if (answerList.size() != answerRecorders.size()) {
                                Log.d(TAG, "#######反序列化成功  size  不同步#############");

                                Log.d(TAG, "#######answerList.size()#############" + answerList.size());

                                Log.d(TAG, "#######answerRecorders.size()#############" + answerRecorders.size());

                                if ((answerRecorders.size() - answerList.size()) == 1) {
                                    baseCallBack.failed(null);
                                } else if ((answerList.size() - answerRecorders.size()) == 1) {

//                                    这种情况由于缓存过程中退出，只缓存其中一个列表记录，造成不同步--neo
                                    int index = answerList.size();
                                    answerList.remove(index - 1);
                                    Log.d(TAG, "#######反序列化成功  answerList.remove(index - 1)############");
                                    baseCallBack.success(answerList);

                                } else {
                                    baseCallBack.failed(null);
                                }

                            } else {
                                Log.d(TAG, "#######反序列化成功  success(answerList)#############");
                                baseCallBack.success(answerList);
                            }

                        } catch (Exception e) {
                            e.getStackTrace();
                        }
                    }

                    @Override
                    public void failed(int errorCode, Object data) {
                        Log.d(TAG, "#######反序列化失败#############");
                        baseCallBack.failed(errorCode, data);
                    }

                    @Override
                    public void failed(Object data) {

                        if (null != data) {
                            Log.d(TAG, "#######反序列化失败 getSaveUserAnswerList failed data.toString()#############" + data.toString());
                        } else {
                            Log.d(TAG, "#######反序列化失败 getSaveUserAnswerList failed#############");

                        }

                        baseCallBack.failed(data);
                    }
                });
    }

    /**
     * 获取保存的做作业记录
     *
     * @param baseCallBack
     */
    protected void getSaveDoWorkRecord(final BaseCallBack baseCallBack, String uuid) {
        Log.d(TAG, "#####getSaveDoWorkRecord mUuid#########" + mUuid);
        String keyDoWork = RepeatKeyUtil.getWordRepeatRecordListKey(mDownLoadInfo, mModule, position, intentWorkId, mUuid);
        SerializableManager.getInstance().deSerialize(keyDoWork,
                new BaseCallBack() {

                    @Override
                    public void success(Object data) {
                        baseCallBack.success(data);
                    }

                    @Override
                    public void failed(int errorCode, Object data) {
                        baseCallBack.failed(errorCode, data);
                    }

                    @Override
                    public void failed(Object data) {
                        baseCallBack.failed(data);
                    }
                });
    }

    /**
     * 保存答案记录和UUID记录
     *
     * @param userAnswersList
     * @param answerRecorderList
     * @param saveUuid
     * @param questioncount
     */
    protected void saveDoWorkRecord(
            ArrayList<WorkAnswers<RepeatAnswerInfo>> userAnswersList,
            ArrayList<AnswerRecorder> answerRecorderList, String saveUuid,
            int questioncount) {

        if ((null == answerRecorderList || null == userAnswersList) || (null != answerRecorderList && userAnswersList != null && answerRecorderList.size() == userAnswersList.size())) {

            if (null != answerRecorderList) {
                Log.d(TAG, "########answerRecorderList.size()###########" + answerRecorderList.size());
            }
            if (userAnswersList != null) {
                Log.d(TAG, "########userAnswersList.size()###########" + userAnswersList.size());
            }

            String key = RepeatKeyUtil.getWordRepeatAnswerListKey(mDownLoadInfo, mModule, position, intentWorkId, saveUuid);
            String keyDoWork = RepeatKeyUtil.getWordRepeatRecordListKey(mDownLoadInfo, mModule, position, intentWorkId, saveUuid);

//           这种情况由于缓存过程中退出，只缓存其中一个列表记录，造成不同步--neo
            SerializableManager.getInstance().serialize(key, userAnswersList);

            SerializableManager.getInstance().serialize(keyDoWork, answerRecorderList);


//            CWSys.setSharedString(RepeatKeyUtil.getUuidSaveKey(mDownLoadInfo, mModule, position, intentWorkId,readMode), saveUuid);
            CWSys.setSharedInt(getSaveQuesCountKey(saveUuid), questioncount);
            CWSys.setSharedInt(getSaveTime(), workLong);
        }

    }


    /**
     * 获取保存题目数量的key
     *
     * @return
     */
    protected String getSaveQuesCountKey(String saveUuid) {
        String key = ESystem.getSaveRecordKeywithModeandUUid(mDownLoadInfo, mModule, position,
                intentWorkId,
                SerializableManager.SerializeKey.SHARE_KEY_QUESTION_COUNT, readMode, saveUuid);
        return key + "_" + getUserInfoBase().getUserId();
    }

    /**
     * 获取作业用时key
     *
     * @return
     */
    protected String getSaveTime() {
        String key = ESystem.getSaveRecordKeywithMode(mDownLoadInfo, mModule, position,
                intentWorkId,
                SerializableManager.SerializeKey.SHARE_KEY_DO_WORK_TIME, readMode);
        return key + "_" + getUserInfoBase().getUserId();
    }

    /**
     * 获取作业开始时间key
     *
     * @return
     */
    protected String getStartTime() {
        String key = ESystem.getSaveRecordKeywithMode(mDownLoadInfo, mModule, position,
                intentWorkId,
                SerializableManager.SerializeKey.SHARE_KEY_DO_WORK_START_TIME, readMode);
        return key + "_" + getUserInfoBase().getUserId();
    }


    @Override
    public void onBackPressed() {
        BaseSpeechActivity.this.goBack();
    }

    /**
     * 清除记录
     */
    protected void clearRecord() {

        Log.d(TAG, "######clearRecord()  saveDoWorkRecord#######");
        saveDoWorkRecord(null, null, mUuid, 0);
        CWSys.setSharedInt(getSaveTime(), 0);
    }

    private ViewOnClickListener clickListener = new ViewOnClickListener(1000) {
        @Override
        public void avertRepeatOnClick(View v) {
            int id = v.getId();
            if (id == R.id.iv_stopOrplay) {
                playOrPause(!mIsAutoPlayPause, false);//播放
            } else if (id == R.id.rl_check_mode) {
                playOrPause(true, false);//播放
                hideCricleProgress();
                //点击切换图标时 暂停流程
                if (isLearn) {
                    if (!speechControler.isPause()) {
                        cancelTimer();
                        speechControler.stop();
                        switchPauseStateForWord();
                    }
                }
                //切换模式
                showCheckModeDailog(mIvCheckMode.isSelected());
            } else if (id == R.id.back_record) {
                //上一个
                goBackWord();
            } else if (id == R.id.next_record) {
                //下一个
                nextWord();
            } else if (id == R.id.img_micro_recording) {
                if (!mIsUnAutoMode) {
                    return;
                }
                //录音
                recordWord();
            } else if (id == R.id.img_stop_recording) {
                //完成、停止录音
                complateRecord();
            } else if (id == R.id.play_dubing_iocn) {
                //设置录音按钮不能重复点击
                //播放录音
                playRecordWord();
            } else if (id == R.id.play_iocn) {
                //播放题目
                playOrPause(false, true);//播放
            }
        }
    };

    static class AnimListener implements AnimationListener {
        private View view;

        private boolean hideAfter;

        public AnimListener(View v, boolean hide) {
            view = v;
            hideAfter = hide;
        }

        @Override
        public void onAnimationEnd(Animation animation) {
            //如果点击再次跟读后，禁止提交，动画完成再使能该提交答案控件
            view.findViewById(R.id.speech_submit_work).setEnabled(true);
            if (hideAfter) {
                view.clearAnimation();
                view.setVisibility(View.GONE);
            }

        }

        @Override
        public void onAnimationRepeat(Animation animation) {

        }

        @Override
        public void onAnimationStart(Animation animation) {

        }
    }

    private void showCheckModeDailog(final boolean isIntensiveReadingModeOpen) {
        CWDialog mDialog = new CWDialog(this);
        String dialogTips;
        if (isIntensiveReadingModeOpen) {
            dialogTips = getString(R.string.instenive_reading_dialog_close_tips);
        } else {
            dialogTips = getString(R.string.instenive_reading_dialog_open_tips);
        }
        // mDialog.setTitle(R.string.lear_title);
        mDialog.setMessage(dialogTips)
                .setPositiveButton(android.R.string.cancel, null)
                .setNegativeButton(R.string.sure,
                        new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                mIvCheckMode.setSelected(!mIvCheckMode.isSelected());
                                mIsUnAutoMode = !isIntensiveReadingModeOpen;
                                setAutoOrUnautoModle();
                                CWSys.setSharedBoolean(EConstants.SHARE_KEY_IS_OPEN_INTENSIVE_READING_MODE, mIsUnAutoMode);
                                //reStartPlay();
                            }
                        }).show();

    }

    private BuyServiceDialog buyServiceDialog;

    public void setBuyServiceDialog() {
        if (buyServiceDialog == null) {
            buyServiceDialog = new BuyServiceDialog(BaseSpeechActivity.this);
            buyServiceDialog.setMenuOnClickListeners(new ViewOnClickListener() {
                @Override
                public void avertRepeatOnClick(View v) {
                    //购买服务包
                    MeJumpManager.jumpBuyService(BaseSpeechActivity.this, R.string.go_back, mServiceId, -1, RequestCode.MainActivityResquestCode.REQUEST_CODE_TO_PAY, "");
                    buyServiceDialog.dismiss();
                }
            });
            buyServiceDialog.setClosOnClickListeners(new ViewOnClickListener() {
                @Override
                public void avertRepeatOnClick(View v) {
                    buyServiceDialog.dismiss();
                }
            });
        }
        buyServiceDialog.show();
    }

    /**
     * 下一个单词
     */
    public abstract void nextWord();

    /**
     * 重读这个单词
     */
    public abstract void repeatWord();

    /**
     * 上一个单词
     */
    public abstract void goBackWord();

    /**
     * 完成录音
     */
    public abstract void complateRecord();

    /**
     * 播放录音
     */
    public abstract void playRecordWord();

    /**
     * 录音
     */
    public abstract void recordWord();

}
